Create a JavaScript function that formats a date according to a specified format string.
date: A Date object representing the date to be formatted.
formatString: A string specifying the desired format (e.g., 'YYYY-MM-DD', 'DD/MM/YYYY', 'MM DD, YYYY').
function formatDate(date, formatString) { // ... }
const currDate = new Date();
const formatString = "DD/MM/YYYY";
const output = document.getElementById("output");
function formatDate(date, formatString) {
const day = date.getDate();
const month = date.getMonth();
const year = date.getFullYear();
const arr = `${day}/${month + 1}/${year}`;
const data = formatString.replace("DD/MM/YYYY", arr);
console.log(data);
output.innerHTML = data;
}
formatDate(currDate, formatString)